<template>
  <div>
    <ul>
      <li v-for="(v,i) in productsArr" :key="i">
        {{v.title}}-${{v.price}}
        <br />
        <button @click="addProduct(v)" :disabled="!v.inventory">添加商品</button>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  methods: {
    ...mapActions("shopping", ["getData"]),
    ...mapActions("car", ["addProduct"])
  },
  computed: {
    ...mapState("shopping", ["productsArr"])
  },
  mounted() {
    this.getData();
  }
};
</script>

<style scoped>
</style>